package com.teach;

import com.sun.istack.internal.NotNull;

public class Demo02 {

	public static void main(String[] args) {

		System.out.println(isHuiWen("上海自来水来自海上"));
		System.out.println(isHuiWen("上海自来水来自海上上"));

//		System.out.println(isHuiWen(null));
	}

	/**
	 * -判断是否是回文字符串
	 * 
	 * @param str
	 * @return
	 * @throws RuntimeException 输入字符串不能为空
	 */
	public static boolean isHuiWen(@NotNull String str) {

		if (str == null || "".equals(str)) {
			throw new RuntimeException("输入字符串不能为空");
		}

		char[] cs = str.toCharArray();

		for (int i = 0; i < cs.length / 2; i++) {
			if (cs[i] != cs[cs.length - i - 1]) {
				return false;
			}
		}

		return true;
	}

}
